package ace.module.product.core.impl.dao.model.bo;

import ace.cmp.data.spring.data.jdbc.querydsl.rsql.core.model.SaveContext;
import ace.cmp.data.spring.data.jdbc.querydsl.rsql.core.model.SaveListContext;
import ace.cmp.data.spring.data.jdbc.querydsl.rsql.core.utils.SaveContextUtils;
import ace.cmp.util.AceStreamUtils;
import ace.module.product.core.impl.dao.entity.PmsCommonGallery;
import ace.module.product.core.impl.dao.entity.PmsProductSku;
import ace.module.product.core.impl.dao.entity.PmsProductSkuAttributeValue;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;
import java.util.stream.Collectors;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

/**
 * .
 * @author Caspar
 *
 */
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class PmsProductSkuSaveListBo {

  @Schema(title = "商品sku")
  private List<PmsProductSkuSaveBo> productSkuSaveBos;

  public SaveListContext<PmsProductSku> getProductSku() {
    List<SaveContext<PmsProductSku>> saveContextList = AceStreamUtils.ofNullable(productSkuSaveBos)
        .map(PmsProductSkuSaveBo::getProductSku)
        .collect(Collectors.toList());

    return SaveContextUtils.toSaveListContext(saveContextList);
  }

  public SaveListContext<PmsCommonGallery> getProductSkuMainImages() {
    List<SaveContext<PmsCommonGallery>> saveContextList = AceStreamUtils.ofNullable(productSkuSaveBos)
        .map(PmsProductSkuSaveBo::getProductSkuMainImage)
        .collect(Collectors.toList());

    return SaveContextUtils.toSaveListContext(saveContextList);
  }

  public SaveListContext<PmsProductSkuAttributeValue> getProductSkuAttributeValues() {
    List<SaveListContext<PmsProductSkuAttributeValue>> saveListContexts = AceStreamUtils.ofNullable(productSkuSaveBos)
        .map(PmsProductSkuSaveBo::getProductSkuAttributeValue)
        .collect(Collectors.toList());

    return SaveContextUtils.mergeSaveListContext(saveListContexts);
  }
}
